package com.zego.wawaji.ui.center.pay.bill;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.utils.StringUtils;
import com.zego.wawaji.ui.base.ExBaseAdapter;
import com.zego.wawaji.ui.center.pay.bean.Consume;

import java.util.List;

/**
 * 消费记录
 * Created by Su on 2017/11/27.
 */
public class ConsumeAdapter extends ExBaseAdapter<Consume> {
    public ConsumeAdapter(Context context, List<Consume> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            convertView = inflate(R.layout.my_consume_record_item);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        final Consume info = getItem(position);
        holder.type_descl.setText(info.getRemark());
        holder.time_info.setText(StringUtils.getCreateTime(info.getCreateTime()));

        holder.ll_coin.setVisibility(View.GONE);
        holder.ll_gold.setVisibility(View.GONE);
        if (info.getWwCoinCz() > 0) {
            holder.ll_gold.setVisibility(View.VISIBLE);
            holder.consume_gold.setText("-" + info.getWwCoinCz());
        }

        if (info.getWwCoinZs() > 0) {
            holder.ll_coin.setVisibility(View.VISIBLE);
            holder.consume_num.setText("-" + info.getWwCoinZs());
        }

        return convertView;
    }

    private class MyViewHolder {
        private TextView type_descl, time_info, consume_num, consume_gold;
        private RelativeLayout ll_coin, ll_gold;

        public MyViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            type_descl = (TextView) convertView.findViewById(R.id.type_descl);
            time_info = (TextView) convertView.findViewById(R.id.time_info);
            consume_num = (TextView) convertView.findViewById(R.id.consume_num);
            consume_gold = (TextView) convertView.findViewById(R.id.consume_gold);
            ll_coin = (RelativeLayout) convertView.findViewById(R.id.ll_coin);
            ll_gold = (RelativeLayout) convertView.findViewById(R.id.ll_gold);
        }
    }
}
